﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using Cairo;
//using Gdk;

namespace FigureDraw
{
    public class CairoGraphic : ScreenDevice
    {
        private int r;
        private int g;
        private int b;

        private Surface s;
        private Context c;

        public CairoGraphic(Surface ss, Context cc)
        {
            r = 255;
            g = 255;
            b = 0;
            this.s = ss;
            this.c = cc;
        }

        public override void drawLine(int x1, int y1, int x2, int y2)
        {
            this.c.Color = new Color(((float)this.r) / 255, ((float)this.g) / 255, ((float)this.b) / 255);
            this.c.MoveTo(x1, y1);
            this.c.LineTo(x2, y2);
            this.c.Stroke();
        }
        public override void drawRect(int x, int y, int width, int height)
        {
            this.c.Color = new Color(((float)this.r) / 255, ((float)this.g) / 255, ((float)this.b) / 255);
            this.c.Rectangle(x - width / 2, y - height / 2, width, height);
            this.c.Stroke();
        }
        public override void drawEllipse(int x, int y, int width, int height)
        {
            this.c.Color = new Color(((float)this.r) / 255, ((float)this.g) / 255, ((float)this.b) / 255);
            this.c.Save();
            int bankinhnho = width / 4;
            int bankinhlon = height / 4;
            this.c.Scale(bankinhnho, bankinhlon);
            if (bankinhnho != 0 && bankinhlon != 0)
            {
                this.c.Arc(x / bankinhnho, y / bankinhlon, 1, 0, 3.14 * 2);
                this.c.Stroke();
            }
            this.c.Restore();
            
        }
        public override void drawString(string s, System.Drawing.Font font, System.Drawing.PointF point)
        {
            throw new NotImplementedException();
        }
        public override void drawArrow(int x1, int y1, int x2, int y2)
        {
            
        }

        public override void drawCurve(System.Drawing.Point[] arrPoint)
        {
            
        }

        public override string ToString()
        {
            return "Cairo";
        }

        public override void ClearAll()
        {
            this.ClearAll();
        }

        public override void setColor(int r, int g, int b)
        {
            
            
            this.r = r;
            this.g = g;
            this.b = b;
            //System.Windows.Forms.MessageBox.Show(r + ":" + g + ":" + b);
        }
        
        public override void setLineWidth(int lw)
        {
            c.LineWidth = (int)lw;
        }
        
    }
}
